import Vue from 'vue'
import Vuex from 'vuex'
import http from '@/until/http'
import persistedstate from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [persistedstate({
    reducer: (state) => {
      return {
        cityId: state.cityId,
        cityName: state.cityName
      }
    }
  })],
  state: {
    cityName: '上海',
    cityId: '440300',
    cinemaList: [],
    isTabberShow: true
  },
  actions: {
    changCinemas (store, cityId) {
      return http({
        url: `/gateway?cityId=${cityId}&ticketFlag=1&k=7819165`,
        headers: {
          'X-Host': 'mall.film-ticket.cinema.list'
        }
      }).then((res) => {
        console.log(res.data.data.cinemas)
        store.commit('changeCinema', res.data.data.cinemas)
      })
    }
  },
  mutations: {
    changeId (state, cityId) {
      state.cityId = cityId
    },
    changeName (state, cityName) {
      state.cityName = cityName
    },
    changeCinema (state, list) {
      console.log(list)
      state.cinemaList = list
    },
    changList (state) {
      state.cinemaList = []
    },
    hide (stat) {
      stat.isTabberShow = false
    },
    show (stat) {
      stat.isTabberShow = true
    }
  }
})
